package com.dnjn.happiness.emo.controller.admin;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dnjn.happiness.common.core.utils.poi.ExcelUtil;
import com.dnjn.happiness.common.cloud.controller.BaseController;
import com.dnjn.happiness.common.core.web.domain.AjaxResult;
import com.dnjn.happiness.common.core.utils.bean.BeanUtils;
import com.dnjn.happiness.common.log.annotation.Log;
import com.dnjn.happiness.common.log.enums.BusinessType;
import com.dnjn.happiness.common.security.utils.SecurityUtils;
import com.dnjn.happiness.emo.domain.UserRecordTask;
import com.dnjn.happiness.emo.domain.vo.UserRecordTaskVO;
import com.dnjn.happiness.emo.service.IUserRecordTaskService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import com.dnjn.happiness.common.security.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 任务派发userRecordTaskController
 * 
 * @author amber
 * @date 2024-01-12
 */
@Tag(name = "emo admin userRecordTask 任务派发userRecordTask", description = "任务派发userRecordTask")
@RestController
@RequestMapping("/admin/userRecordTask")
public class AdminUserRecordTaskController extends BaseController
{
    @Autowired
    private IUserRecordTaskService userRecordTaskService;

    /**
     * 查询任务派发userRecordTask列表
     */
    @RequiresPermissions("emo:userRecordTask:list")
    @PostMapping("/list")
    @Log(title = "emo", businessType = BusinessType.LIST)
    public AjaxResult list(@RequestBody UserRecordTaskVO vo, @RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size) {
        UserRecordTask userRecordTask = new UserRecordTask();
        BeanUtils.copyPropsIgnoreNull(vo, userRecordTask);
        Page page = Page.of(current, size);
        Page<UserRecordTask> list = userRecordTaskService.page(page, Wrappers.query(userRecordTask));
        return success(list);
    }

    /**
     * 导出任务派发userRecordTask列表
     */
    @Log(title = "任务派发userRecordTask", businessType = BusinessType.EXPORT)
    @RequiresPermissions("emo:userRecordTask:export")
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserRecordTaskVO vo) {
        UserRecordTask userRecordTask = new UserRecordTask();
        BeanUtils.copyPropsIgnoreNull(vo, userRecordTask);

        List<UserRecordTask> list = userRecordTaskService.list(Wrappers.query(userRecordTask));
        ExcelUtil<UserRecordTask> util = new ExcelUtil<UserRecordTask>(UserRecordTask.class);
        util.exportExcel(response, list, "任务派发userRecordTask数据");
    }

    /**
     * 获取任务派发userRecordTask详细信息
     */
    @RequiresPermissions("emo:userRecordTask:query")
    @GetMapping(value = "/{taskId}")
    @Log(title = "biz", businessType = BusinessType.SELECT)
    public AjaxResult get(@PathVariable("taskId") Long taskId) {
        return success(userRecordTaskService.getById(taskId));
    }

    /**
     * 新增任务派发userRecordTask
     */
    //@Log(title = "任务派发userRecordTask", businessType = BusinessType.INSERT)
    @RequiresPermissions("emo:userRecordTask:add")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody UserRecordTaskVO vo) {
        UserRecordTask userRecordTask = new UserRecordTask();
        BeanUtils.copyPropsIgnoreNull(vo, userRecordTask);

        userRecordTask.setCreateBy(SecurityUtils.getUsername());
        return toAjax(userRecordTaskService.save(userRecordTask));
    }

    /**
     * 修改任务派发userRecordTask
     */
    @Log(title = "任务派发userRecordTask", businessType = BusinessType.UPDATE)
    @RequiresPermissions("emo:userRecordTask:edit")
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody UserRecordTaskVO vo) {
        UserRecordTask userRecordTask = new UserRecordTask();
        BeanUtils.copyPropsIgnoreNull(vo, userRecordTask);
        return toAjax(userRecordTaskService.updateById(userRecordTask));
    }

    /**
     * 删除任务派发userRecordTask
     */
    @Log(title = "任务派发userRecordTask", businessType = BusinessType.DELETE)
    @RequiresPermissions("emo:userRecordTask:remove")
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds) {
        return toAjax(userRecordTaskService.removeBatchByIds(Arrays.asList(taskIds)));
    }
}
